using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Linq.Extensions;
using HCD.Const;
using HCD.DomainServices.Mdt;
using HCD.Entities;
using HCD.Mdt.Dtos;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;

namespace HCD.Mdt
{
    [Route("api/[controller]/[action]"), ApiController]
    public class MdtGroupAppService : AsyncCrudAppService<MdtGroup, MdtGroupDto, long, MdtGroupGetAllInput, MdtGroupAddInput, MdtGroupEditInput, EntityDto<long>, EntityDto<long>>, IMdtGroupAppService
    {
        public IMdtGroupManager MdtGroupMgr { get; set; }
        public MdtGroupAppService(IRepository<MdtGroup, long> repository)
        : base(repository)
        {
            LocalizationSourceName = EnterpriseConsts.LocalizationSourceName;
        }
        [HttpPost,ActionName("Add"), NonAction]
        public override async Task<MdtGroupDto> CreateAsync(MdtGroupAddInput input)
        {
            return await base.CreateAsync(input);
        }

        [HttpPut, ActionName("Edit"), NonAction]
        public override async Task<MdtGroupDto> UpdateAsync(MdtGroupEditInput input)
        {
            return await base.UpdateAsync(input);
        }
        /// <summary>
        /// 删除Mdt组
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpDelete, ActionName("Delete")]
        public override async Task DeleteAsync(EntityDto<long> input)
        {
            await MdtGroupMgr.DeleteMdtGroup(input.Id);
        }

        [HttpGet, ActionName("Get"), NonAction]
        public override async Task<MdtGroupDto> GetAsync(EntityDto<long> input)
        {
            return await base.GetAsync(input);
        }
        /// <summary>
        /// 分页获取Mdt组
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet, ActionName("GetList")]
        public override async Task<PagedResultDto<MdtGroupDto>> GetAllAsync([FromQuery]MdtGroupGetAllInput input)
        {
            return await base.GetAllAsync(input);
        }
        protected override IQueryable<MdtGroup> CreateFilteredQuery(MdtGroupGetAllInput input)
        {
            return base.CreateFilteredQuery(input)
                .WhereIf(string.IsNullOrWhiteSpace(input.Query), t => t.GroupName.Contains(input.Query));
        }
    }
}


